/*
 * @Author: MarioGo
 * @Date: 2021-11-22 11:04:06
 * @LastEditTime: 2021-11-22 11:04:07
 * @LastEditors: MarioGo
 * @Description: 文件描述
 * @FilePath: /elm-admin-vite/src/store/index.ts
 * 可以输入预定的版权声明、个性签名、空行等
 */
import { createStore } from "vuex";

const defaultState = {
  count: 0,
};

// Create a new store instance.
export default createStore({
  state() {
    return defaultState;
  },
  //同步操作
  mutations: {
    increment(state: typeof defaultState) {
      state.count++;
    },
  },
  //异步操作
  actions: {
    increment(context) {
      context.commit("increment");
    },
  },
  getters: {
    double(state: typeof defaultState) {
      return 2 * state.count;
    },
  },
});